#include "stdafx.h"
#include "EntityBuilderLogin.h"
#include "Entity/EntityL.h"
#include "Entity/EntityP.h"
#include "Combat/CombatSysP.h"



EntityBuilderLogin::EntityBuilderLogin(MsgLoadPlayersEx& msg)
:the_msg(msg)
{
}

EntityBuilderLogin::~EntityBuilderLogin()
{
}

IEntity*
EntityBuilderLogin::build()
{
	IEntity* pEttL = new EntityL;
	pEttL->setGlobalID(the_msg.aid);

	IEntityManager* pEttSubContainer = pEttL->getEntityMgr();

	for (MsgLoadPlayersEx::DBPlayerExList::iterator it = the_msg.players.begin();
		it!=the_msg.players.end();
		it++)
	{
		DBPlayerEx& dbplayer = *it;
		IEntity* pEttSub = new EntityP;
		pEttSub->setGlobalID(dbplayer.pid);
		pEttSub->setStaticID(dbplayer.hid);
		pEttSub->setName(dbplayer.name);
		pEttSub->setLevel(dbplayer.lvl);
		pEttSub->setProps(Entity::ATTR_GENDER, dbplayer.gender);
		pEttSub->setProps(Entity::ATTR_ELVL, dbplayer.elvl);
		pEttSub->setProps(Entity::ATTR_CID, dbplayer.cid);
		pEttSub->setProps(Entity::ATTR_DID, dbplayer.did);
		pEttSub->setProps(Entity::ATTR_SID, dbplayer.sid);

		//
		//	init combat sys for current player
		//	player don't have its owner combat system, but his roles will have combat system
		//	player role combat system will be initiazed after all role is loaded from database
		//	pEttSub->setCombatSys( new CombatSysP );

		pEttSubContainer->addEntity(dbplayer.pid, pEttSub);
	}
	return pEttL;
}
